Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
What difference does it make of accessing through "Object" and through Object.constructor?

I have the following code:

    var obj2 = new Object();
    
    console.log(Object.isExtensible(obj2)); //returns 'true'
    console.log(obj2.constructor.isExtensible()); //returns 'false'

Could anyone explain why the first console print returns boolean 'true' and the second one 'false' and what difference it makes if isExtensible() is called either way.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The .constructor of an instance refers to the class / function that instantiates an instance. Since you're doing

var obj2 = new Object();

this means that obj2.constructor is the same as Object.

So

obj2.constructor.isExtensible()

is calling Object.isExtensible, but without an argument. isExtensible requires an argument. If you pass it the obj2, it'll do what you expect:

var obj2 = new Object();

console.log(Object.isExtensible(obj2)); //returns 'true'
console.log(obj2.constructor.isExtensible(obj2));
console.log(obj2.constructor === Object);

But that's still confusing. I'd recommend never using obj2.constructor - just use Object instead, it'll make more sense.

Usually, you'd probably only want to use the .constructor property when you don't already have a reference to the class - otherwise, it's easier to just reference the class.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!